{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import json"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "# name = \"lipei.json\"\n",
    "# name = \"carinfo.json\"\n",
    "# name = \"carlist.json\"\n",
    "# name = \"car.json\"\n",
    "# name = \"us.json\"\n",
    "# name = \"regulations.json\"\n",
    "# name = \"myscore.json\"\n",
    "# name = \"score.json\"\n",
    "name = \"recharge.json\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [],
   "source": [
    "with open(name, 'r') as f:\n",
    "    info = json.loads(f.read())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [],
   "source": [
    "dic = info['data'][0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "public Integer id;\n",
      "public String tradeNo;\n",
      "public Integer userId;\n",
      "public String userName;\n",
      "public String plan;\n",
      "public String payType;\n",
      "public String payMode;\n",
      "public String payVoucher;\n",
      "public String payDate;\n",
      "public String business;\n",
      "public Integer amount;\n",
      "public String voucherId;\n",
      "public String voucherAmount;\n",
      "public String status;\n",
      "public String delFlag;\n",
      "public Integer createBy;\n",
      "public String createDate;\n",
      "public String updateBy;\n",
      "public String updateDate;\n"
     ]
    }
   ],
   "source": [
    "for key in dic:\n",
    "    output = \"\"\n",
    "    if isinstance(dic[key], int):\n",
    "        output = \"Integer {}\".format(key)\n",
    "    elif isinstance(dic[key], str):\n",
    "        output = \"String {}\".format(key)\n",
    "    elif isinstance(dic[key], float):\n",
    "        output = \"Float {}\".format(key)\n",
    "    else:\n",
    "        output = \"String {}\".format(key)\n",
    "    \n",
    "    print(\"public {};\".format(output))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.DataFrame(info['data']['user'],index=[1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "public String userId;\n",
      "public String username;\n",
      "public String sex;\n",
      "public String idCardName;\n",
      "public String idCardNumber;\n",
      "public String number;\n",
      "public String kind;\n",
      "public String balance;\n",
      "public String deposit;\n",
      "public String integral;\n",
      "public String userGoodsFee;\n",
      "public String mobile;\n",
      "public String email;\n",
      "public String avatar;\n",
      "public String recommendUserId;\n",
      "public String recommendCode;\n",
      "public String deptId;\n",
      "public String lockFlag;\n",
      "public String wxOpenid;\n",
      "public String qqOpenid;\n",
      "public String validateCode;\n",
      "public String invitationCode;\n",
      "public String userType;\n",
      "public String contactName;\n",
      "public String contactMobile;\n",
      "public String delFlag;\n",
      "public String createBy;\n",
      "public String createDate;\n",
      "public String updateBy;\n",
      "public String updateDate;\n"
     ]
    }
   ],
   "source": [
    "for col in df.columns:\n",
    "    print(\"public String {};\".format(col))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_xml_name(actvt):\n",
    "    return \"\".join([\"_\" + i.lower() if i.isupper() else i for i in actvt])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_xml_name(actvt):\n",
    "    return \"\".join([\"_\" + i.lower() if i.isupper() else i for i in actvt])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "a = \"\"\"private TextView mTv{}; \"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "private TextView mTvCompanyId; \n",
      "private TextView mTvEnLogogram; \n",
      "private TextView mTvCompanyName; \n",
      "private TextView mTvCompanyFullname; \n",
      "private TextView mTvCompanyIntroduction; \n",
      "private TextView mTvCompanyWebsite; \n",
      "private TextView mTvCompanyProduct; \n",
      "private TextView mTvCompanyImage; \n",
      "private TextView mTvCompanyAddress; \n",
      "private TextView mTvCompanyCorporate; \n",
      "private TextView mTvCompanyCode; \n",
      "private TextView mTvCompanyScope; \n",
      "private TextView mTvCompanyEmail; \n",
      "private TextView mTvCompanyTelphone; \n",
      "private TextView mTvDelFlag; \n",
      "private TextView mTvCreateDate; \n",
      "private TextView mTvCreateBy; \n",
      "private TextView mTvUpdateDate; \n",
      "private TextView mTvUpdateBy; \n"
     ]
    }
   ],
   "source": [
    "for col in df.columns:\n",
    "    name = col[0].upper() + \"\".join([w for w in col[1:]])\n",
    "    print(a.format(name))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [],
   "source": [
    "a = \"\"\"mTv{}.setText(String.format(\"{}: %s\", oursBean.{}));\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "mTvCompanyId.setText(String.format(\"companyId: %s\", oursBean.companyId));\n",
      "mTvEnLogogram.setText(String.format(\"enLogogram: %s\", oursBean.enLogogram));\n",
      "mTvCompanyName.setText(String.format(\"companyName: %s\", oursBean.companyName));\n",
      "mTvCompanyFullname.setText(String.format(\"companyFullname: %s\", oursBean.companyFullname));\n",
      "mTvCompanyIntroduction.setText(String.format(\"companyIntroduction: %s\", oursBean.companyIntroduction));\n",
      "mTvCompanyWebsite.setText(String.format(\"companyWebsite: %s\", oursBean.companyWebsite));\n",
      "mTvCompanyProduct.setText(String.format(\"companyProduct: %s\", oursBean.companyProduct));\n",
      "mTvCompanyImage.setText(String.format(\"companyImage: %s\", oursBean.companyImage));\n",
      "mTvCompanyAddress.setText(String.format(\"companyAddress: %s\", oursBean.companyAddress));\n",
      "mTvCompanyCorporate.setText(String.format(\"companyCorporate: %s\", oursBean.companyCorporate));\n",
      "mTvCompanyCode.setText(String.format(\"companyCode: %s\", oursBean.companyCode));\n",
      "mTvCompanyScope.setText(String.format(\"companyScope: %s\", oursBean.companyScope));\n",
      "mTvCompanyEmail.setText(String.format(\"companyEmail: %s\", oursBean.companyEmail));\n",
      "mTvCompanyTelphone.setText(String.format(\"companyTelphone: %s\", oursBean.companyTelphone));\n",
      "mTvDelFlag.setText(String.format(\"delFlag: %s\", oursBean.delFlag));\n",
      "mTvCreateDate.setText(String.format(\"createDate: %s\", oursBean.createDate));\n",
      "mTvCreateBy.setText(String.format(\"createBy: %s\", oursBean.createBy));\n",
      "mTvUpdateDate.setText(String.format(\"updateDate: %s\", oursBean.updateDate));\n",
      "mTvUpdateBy.setText(String.format(\"updateBy: %s\", oursBean.updateBy));\n"
     ]
    }
   ],
   "source": [
    "for col in df.columns:\n",
    "    name = col[0].upper() + \"\".join([w for w in col[1:]])\n",
    "    print(a.format(name, col, col))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "a = \"\"\"mTv{} = findViewById(R.id.tv_{});\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "mTvCompanyId = findViewById(R.id.tv_company_id);\n",
      "mTvEnLogogram = findViewById(R.id.tv_en_logogram);\n",
      "mTvCompanyName = findViewById(R.id.tv_company_name);\n",
      "mTvCompanyFullname = findViewById(R.id.tv_company_fullname);\n",
      "mTvCompanyIntroduction = findViewById(R.id.tv_company_introduction);\n",
      "mTvCompanyWebsite = findViewById(R.id.tv_company_website);\n",
      "mTvCompanyProduct = findViewById(R.id.tv_company_product);\n",
      "mTvCompanyImage = findViewById(R.id.tv_company_image);\n",
      "mTvCompanyAddress = findViewById(R.id.tv_company_address);\n",
      "mTvCompanyCorporate = findViewById(R.id.tv_company_corporate);\n",
      "mTvCompanyCode = findViewById(R.id.tv_company_code);\n",
      "mTvCompanyScope = findViewById(R.id.tv_company_scope);\n",
      "mTvCompanyEmail = findViewById(R.id.tv_company_email);\n",
      "mTvCompanyTelphone = findViewById(R.id.tv_company_telphone);\n",
      "mTvDelFlag = findViewById(R.id.tv_del_flag);\n",
      "mTvCreateDate = findViewById(R.id.tv_create_date);\n",
      "mTvCreateBy = findViewById(R.id.tv_create_by);\n",
      "mTvUpdateDate = findViewById(R.id.tv_update_date);\n",
      "mTvUpdateBy = findViewById(R.id.tv_update_by);\n"
     ]
    }
   ],
   "source": [
    "for col in df.columns:\n",
    "    name = col[0].upper() + \"\".join([w for w in col[1:]])\n",
    "    print(a.format(name, get_xml_name(col)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "a = \"\"\"<TextView\n",
    "    android:id=\"@+id/tv_{}\"\n",
    "    style=\"@style/common_text_view\"\n",
    "    android:text=\"{}\"\n",
    "/>\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<TextView\n",
      "    android:id=\"@+id/tv_company_id\"\n",
      "    style=\"@style/common_text_view\"\n",
      "    android:text=\"companyId\"\n",
      "/>\n",
      "<TextView\n",
      "    android:id=\"@+id/tv_en_logogram\"\n",
      "    style=\"@style/common_text_view\"\n",
      "    android:text=\"enLogogram\"\n",
      "/>\n",
      "<TextView\n",
      "    android:id=\"@+id/tv_company_name\"\n",
      "    style=\"@style/common_text_view\"\n",
      "    android:text=\"companyName\"\n",
      "/>\n",
      "<TextView\n",
      "    android:id=\"@+id/tv_company_fullname\"\n",
      "    style=\"@style/common_text_view\"\n",
      "    android:text=\"companyFullname\"\n",
      "/>\n",
      "<TextView\n",
      "    android:id=\"@+id/tv_company_introduction\"\n",
      "    style=\"@style/common_text_view\"\n",
      "    android:text=\"companyIntroduction\"\n",
      "/>\n",
      "<TextView\n",
      "    android:id=\"@+id/tv_company_website\"\n",
      "    style=\"@style/common_text_view\"\n",
      "    android:text=\"companyWebsite\"\n",
      "/>\n",
      "<TextView\n",
      "    android:id=\"@+id/tv_company_product\"\n",
      "    style=\"@style/common_text_view\"\n",
      "    android:text=\"companyProduct\"\n",
      "/>\n",
      "<TextView\n",
      "    android:id=\"@+id/tv_company_image\"\n",
      "    style=\"@style/common_text_view\"\n",
      "    android:text=\"companyImage\"\n",
      "/>\n",
      "<TextView\n",
      "    android:id=\"@+id/tv_company_address\"\n",
      "    style=\"@style/common_text_view\"\n",
      "    android:text=\"companyAddress\"\n",
      "/>\n",
      "<TextView\n",
      "    android:id=\"@+id/tv_company_corporate\"\n",
      "    style=\"@style/common_text_view\"\n",
      "    android:text=\"companyCorporate\"\n",
      "/>\n",
      "<TextView\n",
      "    android:id=\"@+id/tv_company_code\"\n",
      "    style=\"@style/common_text_view\"\n",
      "    android:text=\"companyCode\"\n",
      "/>\n",
      "<TextView\n",
      "    android:id=\"@+id/tv_company_scope\"\n",
      "    style=\"@style/common_text_view\"\n",
      "    android:text=\"companyScope\"\n",
      "/>\n",
      "<TextView\n",
      "    android:id=\"@+id/tv_company_email\"\n",
      "    style=\"@style/common_text_view\"\n",
      "    android:text=\"companyEmail\"\n",
      "/>\n",
      "<TextView\n",
      "    android:id=\"@+id/tv_company_telphone\"\n",
      "    style=\"@style/common_text_view\"\n",
      "    android:text=\"companyTelphone\"\n",
      "/>\n",
      "<TextView\n",
      "    android:id=\"@+id/tv_del_flag\"\n",
      "    style=\"@style/common_text_view\"\n",
      "    android:text=\"delFlag\"\n",
      "/>\n",
      "<TextView\n",
      "    android:id=\"@+id/tv_create_date\"\n",
      "    style=\"@style/common_text_view\"\n",
      "    android:text=\"createDate\"\n",
      "/>\n",
      "<TextView\n",
      "    android:id=\"@+id/tv_create_by\"\n",
      "    style=\"@style/common_text_view\"\n",
      "    android:text=\"createBy\"\n",
      "/>\n",
      "<TextView\n",
      "    android:id=\"@+id/tv_update_date\"\n",
      "    style=\"@style/common_text_view\"\n",
      "    android:text=\"updateDate\"\n",
      "/>\n",
      "<TextView\n",
      "    android:id=\"@+id/tv_update_by\"\n",
      "    style=\"@style/common_text_view\"\n",
      "    android:text=\"updateBy\"\n",
      "/>\n"
     ]
    }
   ],
   "source": [
    "for col in df.columns:\n",
    "    print(a.format(get_xml_name(col), col))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {},
   "outputs": [],
   "source": [
    "a = '// \"SN_FINDCAR\"//寻车;\"SN_OPENTRUNK\"//座位锁;\"SN_STALLING\"//断电;\"SN_IGNITION\"//上电;\"SN_SAFEON\"//车门上锁;\"SN_SAFEOFF\"//车门解锁;'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'// \"SN_FINDCAR\"//寻车;\"SN_OPENTRUNK\"//座位锁;\"SN_STALLING\"//断电;\"SN_IGNITION\"//上电;\"SN_SAFEON\"//车门上锁;\"SN_SAFEOFF\"//车门解锁;'"
      ]
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['// \"SN_FINDCAR\"//寻车',\n",
       " '\"SN_OPENTRUNK\"//座位锁',\n",
       " '\"SN_STALLING\"//断电',\n",
       " '\"SN_IGNITION\"//上电',\n",
       " '\"SN_SAFEON\"//车门上锁',\n",
       " '\"SN_SAFEOFF\"//车门解锁',\n",
       " '']"
      ]
     },
     "execution_count": 102,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "metadata": {},
   "outputs": [],
   "source": [
    "template = 'public static final String {} = {};'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "public static final String SN_FINDCAR = // \"SN_FINDCAR\"//寻车;\n",
      "public static final String SN_OPENTRUNK = \"SN_OPENTRUNK\"//座位锁;\n",
      "public static final String SN_STALLING = \"SN_STALLING\"//断电;\n",
      "public static final String SN_IGNITION = \"SN_IGNITION\"//上电;\n",
      "public static final String SN_SAFEON = \"SN_SAFEON\"//车门上锁;\n",
      "public static final String SN_SAFEOFF = \"SN_SAFEOFF\"//车门解锁;\n"
     ]
    },
    {
     "ename": "IndexError",
     "evalue": "list index out of range",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mIndexError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-112-cff77a9580e4>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[0;32min\u001b[0m \u001b[0ma\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msplit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\";\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m     \u001b[0mvar\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mi\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msplit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"\\\"\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      3\u001b[0m     \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtemplate\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mvar\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mi\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mIndexError\u001b[0m: list index out of range"
     ]
    }
   ],
   "source": [
    "for i in a.split(\";\"):\n",
    "    var = i.split(\"\\\"\")[1]\n",
    "    print(template.format(var, i))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
